<?php
// +----------------------------------------------------------------------
// | 动态栏目
// +----------------------------------------------------------------------

namespace Home\Controller;
use Common\Controller\Base;
use Common\Model\Model;
use Think\Controller;
class DongtaiController extends Base {

    //最新
    public function index(){
        $this->workslist('create_time','index');
        $this->assign('newact','act');
        $this->assign('stitle','最新上传');
        $this->display();
    }

    public function liuxin(){
        $this->workslist('msgnum','liuxin');
        $this->assign('liuxinact','act');
        $this->assign('stitle','正在流行作品');
        $this->display('index');
    }

    public function zuijia(){
        $this->workslist('favoritenum','zuijia');
        $this->assign('zuijiaact','act');
        $this->assign('stitle','24小时最佳');
        $this->display('index');
    }

    public function workslist($type,$url){

        //中间广告位
        $this->assign('midad',parent::getAdvert(2,1,0,1));

        $worksModel=M('Works');
        $where['status']=array('EQ',true);
        $where['type']=array('EQ',1);

        $count = $worksModel->where($where)->count();
        $page = $this->Pages($count, 15);
        $pageurl='?page='.urlencode('[PAGE]');
        $page->url     = __APP__.'/dongtai/'.$url.'/'.$pageurl;


        $Model=new Model();
        $list=$Model
            ->table(array(
                    C('DB_PREFIX').'works'=>'W',
                    C('DB_PREFIX').'user'=>'U',
                )
            )
            ->where('W.userid=U.userid and W.status=true and W.type=1')
            ->field('W.title,W.content,W.goodnum,W.msgnum,W.workid,W.create_time,W.image,U.nickname,U.uavatar,U.openuid,U.uprovince,U.ucity,U.userid,U.ifrz')
            ->order(''.$type.' DESC')
            ->limit($page->firstRow . ',' . $page->listRows)
            ->select();
        foreach ($list as $key=>$value) {
            $list[$key]['dignum']=M('Dig')->where(array('status'=>true,'infoid'=>$value['workid'],'userid'=>$this->userid))->count();
        }

        $this->pagecount=$page->totalRows/$page->listRows;

        $this->assign("list", $list);
        $this->assign("Page", $page->show());
    }
    

}